import 'user_entity.dart';
import 'package:myapp/models/models.dart';





class ArticleEntity {
  String slug;
  String title;
  String description;
  String body;
  List<String> tagList;
  DateTime createdAt;
  DateTime updatedAt;
  bool favorited;
  int favoritesCount;
  MyUser author;

  ArticleEntity(
      {required this.slug,
      required this.title,
      required this.description,
      required this.body,
      required this.tagList,
      required this.createdAt,
      required this.updatedAt,
      required this.favorited,
      required this.favoritesCount,
      required this.author});

  Map<String, Object?> toDocument() {
    return {
      'slug': slug,
      'title': title,
      'description': description,
      'body': body,
      'tagList': tagList,
      'createdAt': createdAt,
      'updatedAt': updatedAt,
      'favorited': favorited,
      'favoritesCount': favoritesCount,
      'author': author.toEntity().toDocument()
    };
  }

  static ArticleEntity fromDocument(Map<String, dynamic> doc) {
    return ArticleEntity(
      slug: doc['slug'],
      title: doc['title'],
      description: doc['description'],
      body: doc['body'],
      tagList: doc['tagList'],
      createdAt: doc['createdAt'],
      updatedAt: doc['updatedAt'],
      favorited: doc['favorited'],
      favoritesCount: doc['favoritesCount'],
      author: MyUser.fromEntity(MyUserEntity.fromDocument(doc['author'])),
    );
  }
  
}
